import { Component, OnInit } from '@angular/core';
import { CallService } from '../call.service';

@Component({
  selector: 'app-words',
  templateUrl: './words.page.html',
  styleUrls: ['./words.page.scss'],
})
export class WordsPage implements OnInit {
  words = [];
  private start = '';
  constructor(
    private callService: CallService,
  ) { }
  async ngOnInit() {
    this.words = await this.callService.call('getWords', {
      def: [
        { id: 1, word: 'test', count: 3 },
        { id: 2, word: 'book', count: 300 },
      ]
    }, '');
  }
  // 加载数据
  async loadData(event: any) {
    const ws = await this.callService.call('getWords', { def: [] }, this.start);

    ws.shift();

    if (ws.length > 0) {
      this.start = ws[ws.length - 1].word;
    }

    this.words.push(...ws);
    event.target.complete();

    if (ws.length === 0) {
      event.target.disabled = true;
    }
  }
}
